package com.kxf.rpc;

import cn.hutool.core.thread.ThreadUtil;
import com.kxf.rpc.handler.HandlerThread;
import com.kxf.rpc.handler.JdkHandler;
import com.kxf.rpc.impl.HelloImpl;
import com.kxf.rpc.provider.RedisServiceProvider;
import com.kxf.rpc.serializer.CommonSerialize;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;

/**
 * @author Kxf
 * @create 2021/9/23,0023 15:14
 */
public class ServerMain {

    public static void main(String[] args) throws IOException {
        new RedisServiceProvider().addProvider(new HelloImpl(), Hello.class.getName(),
                new InetSocketAddress("127.0.0.1", 9999));
        ServerSocket serverSocket = new ServerSocket(9999);
        ExecutorService pool = ThreadUtil.newExecutor(10);
        Socket socket;
        while ((socket = serverSocket.accept()) != null) {
            //Json序列化
            //pool.execute(new HandlerThread(socket, CommonSerialize.getByteCode(0), new JdkHandler()));

            //Kryo序列化
            //pool.execute(new HandlerThread(socket, CommonSerialize.getByteCode(1), new JdkHandler()));

            //Protostuff序列化
            pool.execute(new HandlerThread(socket, CommonSerialize.getByteCode(2), new JdkHandler()));
        }
    }
}
